package com.yyf.blogapi.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yyf.blogapi.po.ArticleTag;
import com.yyf.blogapi.mapper.ArticleTagMapper;
import com.yyf.blogapi.service.IArticleTagService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author yyf
 * @since 2021-08-16
 */
@Service
public class ArticleTagServiceImpl extends ServiceImpl<ArticleTagMapper, ArticleTag> implements IArticleTagService {
    @Resource
    ArticleTagMapper articleTagMapper;

    @Override
    public List<Long> getArticleIdByTagId(Long tagId) {
        LambdaQueryWrapper<ArticleTag> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(ArticleTag::getTagId, tagId);
        List<ArticleTag> articleTags = articleTagMapper.selectList(queryWrapper);
        List<Long> articleIds = new ArrayList<>();
        for (ArticleTag articleTag : articleTags) {
            articleIds.add(articleTag.getArticleId());
        }
        return articleIds;
    }
}
